<?php

class Core_Backend_Component_Website_View_Menu_Create extends Core_Backend_Share_View_Form {

    public function __construct() {
        parent::__construct();
        $this->setTemplatePath('edit');
    }

    protected function buildNavigation($navigation) {
        $navigation->addLabel($this->__f('website.title.menu_create', $this->getArea()->getName()));
        parent::buildNavigation($navigation);
    }

    protected function buildToolbar($toolbar) {
    	$group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('website/menu/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.apply'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'apply')."')");
        $group->addButton($this->__('share.button.save'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'save')."')");
        parent::buildToolBar($toolbar);
    }

    public function buildForm($form) {
        $entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())
                ->setId('menu_form')
                ->addHiddenField('id', 'menu[id]')
                ->addHiddenField('area_id', 'menu[area_id]', $this->getArea()->getId());
        $form->addTextboxField($this->__('share.label.name'), 'name', 'menu[name]', TRUE)
                ->addMultiRule('required');
        $form->addTextboxField($this->__('share.label.url'), 'url', 'menu[url]', TRUE)
                ->addRequiredRule();
        $form->addTextboxField($this->__('share.label.sef_url'), 'sef_url', 'menu[sef_url]', TRUE)
                ->addRequiredRule();
        $form->addSelectField($this->__('share.label.enable'), 'enabled', 'menu[enabled]', TRUE)
                ->addRequiredRule()
                ->addOption(Kd_Localize_Helper::getLanguageItems('status.boolean'));
        $parents = $this->getParentMenus()->toArray();
        array_unshift($parents, array('id'=>-1, 'parent_id'=>0, 'name'=>'--'));
        $form->addComboTreeField($this->__('article.label.parent_category'), 'parent_id', 'menu[parent_id]', TRUE)
                ->bindData($parents, 0, array('valueKey'=>'id', 'parentKey'=>'parent_id', 'textKey'=>'name', 'childKey'=>'id'))
                ->addRequiredRule();
        if (!is_null($entity)) {
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }

}

